﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WAI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void runWizardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WAI_Wizard wizard = new WAI_Wizard();
            wizard.ShowDialog(); 
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream WAI_config_file = null;
            OpenFileDialog openWAI_config_file = new OpenFileDialog();


            if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WAI") == false)
            {
                openWAI_config_file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            }
            else
            {
                openWAI_config_file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WAI";
            }

            
            openWAI_config_file.Filter = "WAI files (*.wai)|*.wai|All files (*.*)|*.*";
            openWAI_config_file.FilterIndex = 1;
            openWAI_config_file.RestoreDirectory = true;
            openWAI_config_file.Title = "Open WAI-Project";

            if (openWAI_config_file.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((WAI_config_file = openWAI_config_file.OpenFile()) != null)
                    {
                        using (WAI_config_file)
                        {
                            // Insert code to read the stream here.
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }

        }

        private void saveProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream WAI_config_file = null;
            SaveFileDialog saveWAI_config_file = new SaveFileDialog();


            if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WAI") == false)
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WAI");
            }

            saveWAI_config_file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WAI";
            saveWAI_config_file.Filter = "WAI files (*.wai)|*.wai|All files (*.*)|*.*";
            saveWAI_config_file.FilterIndex = 1;
            saveWAI_config_file.RestoreDirectory = true;
            saveWAI_config_file.FileName = "Testprojekt";
            saveWAI_config_file.Title = "Save WAI-Project";

            if (saveWAI_config_file.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (true)
                    {
                        using (WAI_config_file)
                        {
                            // Insert code to read the stream here.
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not write file to disk. Original error: " + ex.Message);
                }
            }
        }
    }
}
